package com.hliushi.learn.exception;

/**
 * @ClassName BusinessErrorException
 * @Description 拦截自定义异常
 * @Author hliushi
 * @Date 2021/7/7 8:52
 * @Version V1.0
 **/
public class BusinessErrorException extends RuntimeException {

    /**
     * 定义一个业务异常, 当出现业务异常时, 我们就抛出这个自定义的业务异常即可
     */
    private static final long serialVersionUID = 9059317567370621824L;


    /**
     * 状态码
     */
    private String code;

    /**
     * 异常提示信息
     */
    private String message;


    /**
     * 在构造方法中, 传入我们上面自定义的异常枚举类, 所以在项目中, 如果有新的异常信息需要添加
     * 我们直接在枚举类中添加即可, 很方便, 做到统一维护, 然后在拦截该异常时获取即可
     *
     * @param businessMsgEnum
     */
    public BusinessErrorException(BusinessMsgEnum businessMsgEnum) {
        this.code = businessMsgEnum.getCode();
        this.message = businessMsgEnum.getMsg();
    }


    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
